scheme, netloc, path, query, fragment = urlparse.urlsplit(st)
u = klass(
scheme, netloc,
[urllib.unquote(seg) for seg in path.split('/')[1:]],
unquerify(query), fragment)
return u
fromString = classmethod(fromString)
def fromRequest(klass, request):
"""
Create a new L{URL} instance which is the same as the URL represented
by C{request} except that it includes only the path segments which have
already been processed.
"""
uri = request.prePathURL()
if '?' in request.uri:
uri += '?' + request.uri.split('?')[-1]
return klass.fromString(uri)
fromRequest = classmethod(fromRequest)
def fromContext(klass, context):
'''Create a URL object that represents the current URL in the traversal
process.'''
request = inevow.IRequest(context)
uri = request.prePathURL()
if '?' in request.uri:
uri += '?' + request.uri.split('?')[-1]
return klass.fromString(uri)
fromContext = classmethod(fromContext)
## path manipulations ##
def pathList(self, unquote=False, copy=True):
result = self._qpathlist
if unquote:
result = map(urllib.unquote, result)
if copy:
result = result[:]
return result
def sibling(self, path):
"""Construct a url where the given path segment is a sibling of this url
"""
l = self.pathList()
l[-1] = path
return self._pathMod(l, self.queryList(0))
def child(self, path):
"""Construct a url where the given path segment is a child of this url
"""
l = self.pathList()
if l[-1] == '':
l[-1] = path
else:
l.append(path)
return self._pathMod(l, self.queryList(0))
def isRoot(self, pathlist):
return (pathlist == [''] or not pathlist)
def parent(self):
import warnings
warnings.warn(
"[v0.4] URL.parent has been deprecated and replaced with parentdir (which does what parent used to do) and up (which does what you probably thought parent would do ;-))",
DeprecationWarning,
stacklevel=2)
return self.parentdir()
def curdir(self):
"""Construct a url which is a logical equivalent to '.'